package com.hna.face.util;

import java.io.File;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;

public class LibLoader {
//    public static void loadLib(String libName) {
//        String resourcePath = "/lib/" + libName;
//        String folderName = "/home/HNAFace/lib/";
//        File folder = new File(folderName);
//        folder.mkdirs();
//        File libFile = new File(folder, libName);
//        if (libFile.exists()) {
//            System.load(libFile.getAbsolutePath());
//        } else {
//            try {
//                InputStream in = LibLoader.class.getResourceAsStream(resourcePath);
//                FileUtils.copyInputStreamToFile(in,libFile);
//                in.close();
//                System.load(libFile.getAbsolutePath());
//            } catch (Exception e) {
//                e.printStackTrace();
//                throw new RuntimeException("Failed to load required lib", e);
//            }
//        }
//    }
    
    public static void loadAts(String bindata) {
        String resourcePath = "/bindata/" + bindata;
        String folderName = "/home/HNAFace/Seeta/bindata";
        File folder = new File(folderName);
        folder.mkdirs();
        File libFile = new File(folder, bindata);
        if (libFile.exists()) {
            
        } else {
            try {
                InputStream in = LibLoader.class.getResourceAsStream(resourcePath);
                FileUtils.copyInputStreamToFile(in,libFile);
                in.close();
                
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Failed to load required ats", e);
            }
        }
    }
    
    public static void loadTestImage() {
    	String imagePath = "001.jpg";
        String resourcePath = "/test/" + imagePath;
        String folderName = "/home/HNAFace/Images/base/";
        File folder = new File(folderName);
        folder.mkdirs();
        File libFile = new File(folder, imagePath);
        if (libFile.exists()) {
            
        } else {
            try {
                InputStream in = LibLoader.class.getResourceAsStream(resourcePath);
                FileUtils.copyInputStreamToFile(in,libFile);
                in.close();
                
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Failed to load test image", e);
            }
        }
    }
}
